<template>
  <view class="cart">
    <!-- button获取用户数据列表 -->
    <view class="address-btn u-flex u-row-center" v-if="!address">
      <u-button
        shape="circle"
        type="error"
        plain
        size="medium"
        @click="handleChooseAddress"
        :custom-style="{ backgroundColor: '#fff!important' }"
        >获取收获地址</u-button
      >
    </view>
    <view v-else class="address-detail">
      <view class="address-detail">{{ addressDetail }}</view>
      <view class="address-user"
        >{{ address.userName }} {{ address.telNumber }}
      </view>
    </view>

    <!-- 商品列表 -->
    <view class="cart-list" v-for="item in cart_goods" :key="item.goods_id">
      <view class="cart-item">
        <!-- 1 复选框 -->
        <!-- <view class="goods-chk">
          <u-checkbox
            :value="item.checked"
            shape="circle"
            active-color="red"
            @change="checkClickFn(item.goods_id)"
          ></u-checkbox>
        </view> -->
        <!-- 2 图片 -->
        <view class="goods-img">
          <u-image
            width="191rpx"
            height="191rpx"
            :src="item.goods_small_logo"
          ></u-image>
        </view>
        <!-- 3 信息 -->
        <view class="goods-info">
          <!-- 名称 -->
          <view class="goods-name u-line-2">{{ item.goods_name }}</view>
          <!-- 价格和数量 -->
          <view class="goods-price-num">
            <view class="goods-price">￥{{ item.goods_price }}</view>
            <view class="goods-num-tool">
              <view class="goods-vnum">X{{ item.count }}</view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <!-- 商品列表 -->
  </view>
</template>

<script>
export default {
  methods: {
    //点击获取收获地址
    async handleChooseAddress() {
      const res = await wx.chooseAddress();
      console.log(res);
      //将获取到的数据返回到address中
      this.cityName = res.cityName;
      this.countyName = res.countyName;
      this.detailInfo = res.detailInfo;
      this.userName = res.userName;
      this.telNumber = res.telNumber;
    },
  },
  onLoad() {},
  data() {
    return {
      cityName: "",
      countyName: "",
      detailInfo: "",
      userName: "",
      telNumber: "",
    };
  },

  computed: {
    cart_goods() {
      return this.$store.state.cart.cart.filter((item) => item.checked == true);
    },
    address() {
      return `this.cityName+this.countyName+this.detailInfo` 
    },
  },
};
</script>

<style lang="scss">
.cart {
  padding-bottom: 111rpx;
  .cart-list {
    .cart-item {
      display: flex;
      padding: 10rpx;
      border-bottom: 1rpx solid #ccc;
      .goods-chk {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
      }

      .goods-img {
        flex: 2;

        display: flex;
        align-items: center;
        justify-content: center;
      }

      .goods-info {
        color: #666;
        flex: 3;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        .goods-name {
        }

        .goods-price-num {
          display: flex;
          justify-content: space-between;
          .goods-price {
            color: red;
          }

          .goods-num-tool {
            width: 140rpx;
            height: 40rpx;

            display: flex;
            justify-content: space-between;
            .num-btn {
              border: 1rpx solid #ccc;
              border-radius: 50%;
              width: 40rpx;
              height: 40rpx;
              text-align: center;
              line-height: 40rpx;
            }

            .goods-vnum {
            }
          }
        }
      }
    }
  }
  .statistics {
    position: fixed;
    background-color: #fff;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    border-top: 1rpx solid #ccc;
    display: flex;
    align-items: center;
    padding: 15rpx;
    .all-chk {
    }

    .all-price {
      flex: 1;
      color: #666;
      text {
      }
    }

    .all-count {
    }
  }
}
</style>